package com.drug.mingkang.config;

/**
 * 描述：
 *
 * @version 1.0
 * @author: wcj
 * @Date: 2020/7/13 16:14
 */

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Configuration;

/**
 * 配置项目 启动浏览器
 * @author wcj
 */
@Configuration
public class IndexConfig implements CommandLineRunner {
//    @EventListener({ApplicationReadyEvent.class})
//    void applicationReadyEvent() {
//        System.out.println("应用已经准备就绪 ... 启动浏览器");
//        String url = "http://localhost:8090/ok-admin/pages/login.html";
//        Runtime runtime = Runtime.getRuntime();
//        try {
//            runtime.exec("rundll32 url.dll,FileProtocolHandler " + url);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }

    @Override
    public void run(String... args) throws Exception {
        String url = "http://localhost:8090/ok-admin/pages/login.html";
        try {
            //当前运行的环境
            String osName = System.getProperty("os.name");
            System.out.println("当前操作系统是:"+osName);
            if(osName.indexOf("Window")>-1){
                Runtime.getRuntime().exec("cmd   /c   start   "+url);
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

